import Banner from "../Banner";
import GameManager from "../GameManager";

const { ccclass, property } = cc._decorator;

export enum End {
    结局1 = "胖胖鲨",
    结局2 = "口碑太差的饲主",
    结局3 = "流浪的鲨鱼",
    结局4 = "被视作无用的鲨鱼",
    结局5 = "横纹肌溶解",
    结局6 = "失眠的鲨鱼",
    结局7 = "反悔的饲主",
    结局8 = "成为养料的鲨鱼",
    结局9 = "破镜难圆",
    结局10 = "与你无关的事物",
    结局11 = "一个人也很自在",
}

@ccclass
export default class Ending extends cc.Component {
    public static EndName: string[] = ["胖胖鲨", "口碑太差的饲主", "流浪的鲨鱼", "被视作无用的鲨鱼", "横纹肌溶解", "失眠的鲨鱼", "反悔的饲主",
        "成为养料的鲨鱼", "破镜难圆", "与你无关的事物", "一个人也很自在"];
    // onLoad () {}

    start() {
        let light = this.node.getChildByName("光");
        let title = this.node.getChildByName("标题");
        cc.tween(light)
            .to(3, { angle: 360 })
            .call(() => {
                light.angle = 0;
            })
            .union()
            .repeatForever()
            .start()
        cc.tween(light)
            .to(0.5, { scale: 1.2 })
            .to(0.5, { scale: 1 })
            .union()
            .repeatForever()
            .start()

        cc.tween(light)
            .to(1, { opacity: 200 })
            .to(1, { opacity: 255 })
            .union()
            .repeatForever()
            .start()

        cc.tween(title)
            .to(1, { position: cc.v3(title.x, title.y + 10), scale: 1.05 })
            .to(1, { position: cc.v3(title.x, title.y), scale: 1 })
            .union()
            .repeatForever()
            .start()

    }

    Init(end: End) {
        let jieju = this.node.getChildByName("结局");
        let desc = this.node.getChildByName("Desc");
        let img = this.node.getChildByName("Img");
        jieju.getComponent(cc.Label).string = GameManager.Instance.GetEnumKey(End, end);
        desc.getComponent(cc.Label).string = end;
        let _scale = img.scale;
        img.scale = 0;
        GameManager.Instance.LoadSpriteFrame("Sprits", "结局/" + end, (spf: cc.SpriteFrame) => {
            if (!Banner.IsBlackWhite) {//正常包模式
                Banner.Instance.ShowNativeAd();
            } else {//黑白包模式
                if (Banner.cityIswhite) {//黑包
                    Banner.Instance.ShowNativeAd();
                    Banner.Instance.ShowVideo(() => { });
                } else {//白包
                    Banner.Instance.ShowNativeAd();
                }
            }
            this.node.getChildByName("Img").getComponent(cc.Sprite).spriteFrame = spf;
            cc.tween(img)
                .to(1, { scaleX: _scale + 0.02, scaleY: _scale - 0.02, angle: 5 })
                .to(1, { scaleX: _scale - 0.02, scaleY: _scale + 0.02, angle: -5 })
                .union()
                .repeatForever()
                .start()
            this.node.once(cc.Node.EventType.TOUCH_END, () => {
                cc.director.loadScene("Game");
            })
            cc.tween(jieju)
                .to(1, { position: cc.v3(jieju.x, jieju.y + 10), scale: 1.05 })
                .to(1, { position: cc.v3(jieju.x, jieju.y), scale: 1 })
                .union()
                .repeatForever()
                .start()
            cc.tween(desc)
                .to(1, { position: cc.v3(desc.x, desc.y + 10), scale: 1.05 })
                .to(1, { position: cc.v3(desc.x, desc.y), scale: 1 })
                .union()
                .repeatForever()
                .start()
        })
        GameManager.Instance.SetEndingFinish(end, 1);//结局达成，作为其他隐藏彩蛋的判断依据
    }

}
